/*
	Anonymous Image Board Image Downloader - program for downloading pictures from AIB
	Copyright (C) 2011-2012 Metallhead <Metallhead@megabox.ru>

	HomePage:    http://code.google.com/p/aibid/

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "threadinfo.h"
#include "ui_threadinfo.h"

threadInfo::threadInfo(QString url, QString path, QString status, int timeRemains, int imagesDownloaded, int imageCount,
					   QDateTime additionTime, int imagesInFolder, int threadsCount, int updateTime, QWidget *parent) :
    QDialog(parent),
	ui(new Ui::threadInfo)
{
    ui->setupUi(this);
	ui->url->setText(url);
	ui->path->setText(path);
	ui->status->setText(status);

	QString format;
	if((timeRemains)/3600)
		format = "hh:mm:ss";
	else
		format = "mm:ss";
	QTime time((timeRemains)/3600,((timeRemains)/60)%60,(timeRemains)%60);
	ui->timeUntilUpdate->setText(time.toString(format));
	ui->threadsCount->setText(QString::number(threadsCount));
	ui->updateInterval->setText(QString::number(updateTime));
	ui->imagesDownloaded->setText(QString::number(imagesDownloaded));
	ui->imageCount->setText(QString::number(imageCount));
	ui->additionTime->setText(additionTime.toString("dd-MM-yyyy hh:mm"));
	ui->imagesInFolder->setText(QString::number(imagesInFolder));
}

threadInfo::~threadInfo()
{
    delete ui;
}

void threadInfo::on_pushButton_clicked()
{
	this->close();
}

void threadInfo::updateInfo(bool usualData, int data1, int data2)
{
	if(usualData)
	{
		ui->imagesDownloaded->setText(QString::number(data1));
		ui->imageCount->setText(QString::number(data2));
	}
	else
	{
		ui->imagesInFolder->setText(QString::number(data2));
	}
}

void threadInfo::updateInfo(QString status, int timeRemains)
{
	ui->status->setText(status);
	QString format;
	if((timeRemains)/3600)
		format = "hh:mm:ss";
	else
		format = "mm:ss";
	QTime time((timeRemains)/3600,((timeRemains)/60)%60,(timeRemains)%60);
	ui->timeUntilUpdate->setText(time.toString(format));
}
